/*
 * LoggerBuffer.cpp
 *
 *  Created on: Nov 5, 2009
 *      Author: adailton
 */

#include "../include/LoggerBuffer.h"

//#define MAX_TAMANHO 1024
#define MAX_TAMANHO 1

std::vector<std::string> LoggerBuffer::mBuffer;
LoggerBuffer            *LoggerBuffer::mInstance = NULL;

LoggerBuffer::LoggerBuffer()
{
}

LoggerBuffer::~LoggerBuffer()
{
}

/*static*/
LoggerBuffer&
LoggerBuffer::getInstance()
{
	if (mInstance == NULL)
	{
		//time_t curr_time;
		//std::time(&curr_time);
		//struct tm * t = std::localtime(&curr_time);

		mInstance = new LoggerBuffer();

		//fprintf(stdout, "%i:%i:%i - info - Logger Buffer Instanciado!\n",
		//        t->tm_hour, t->tm_min, t->tm_sec);
		fflush(stdout);
	}

    return *mInstance;
}

void
LoggerBuffer::armazenarLogger(std::string log)
{
    mBuffer.push_back(log);
}


void
LoggerBuffer::imprimirLogger()
{
    if (mBuffer.size() >= MAX_TAMANHO)
    {
        for (std::vector<std::string>::iterator it = mBuffer.begin();
                it != mBuffer.end(); it++)
        {
            std::string logger = (*it);
            fprintf(stdout, "%s\n", logger.c_str());
            fflush(stdout);
        }
        mBuffer.clear();
    }
}

void
LoggerBuffer::forceImprimirLogger()
{
    for (std::vector<std::string>::iterator it = mBuffer.begin();
            it != mBuffer.end(); it++)
    {
        std::string logger = (*it);
        fprintf(stdout, "%s\n", logger.c_str());
        fflush(stdout);
    }
    mBuffer.clear();
}

